package com.zhangliuliu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangliuliu.bean.InsectPestBean;
import com.zhangliuliu.dao.InsectPestDao;
import com.zhangliuliu.service.InsectPestService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class InsectPestServiceImpl extends ServiceImpl<InsectPestDao, InsectPestBean> implements InsectPestService {
    @Override
    public void addPest(InsectPestBean insectPestBean) {
        save(insectPestBean);
    }

    @Override
    public InsectPestBean select(int id) {
     InsectPestBean byId = getById(id);
        return byId;
    }

    @Override
    public IPage<InsectPestBean> cutByItem(int pageNo, int pageSize, String name, String host) {
        Page<InsectPestBean> page = new Page<>(pageNo, pageSize);
      QueryWrapper wrapper = new QueryWrapper();
      if (name!=null&&!name.equals("")){
          wrapper.eq("pest_name",name);
      }
   if (host!=null&&!host.equals("")){
       wrapper.eq("host",host);
   }

   IPage<InsectPestBean> page1= this.page(page, wrapper);
    return page1;
    }

    @Override
    public IPage<InsectPestBean> cut(int pageNo, int pageSize, String name, String host,String harm) {
        Page<InsectPestBean> page = new Page<>(pageNo, pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (name!=null&&!name.equals("")){
            wrapper.eq("pest_name",name);
        }
        if (host!=null&&!host.equals("")){
            wrapper.eq("host",host);
        }
        if (harm!=null&& !harm.equals("")){
            wrapper.eq("harm",harm);
        }

        IPage<InsectPestBean> page1= this.page(page, wrapper);
        return page1;

    }


}
